package th.go.drr.gps.services;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import th.go.drr.gps.domain.Province;
import th.go.drr.gps.repository.cache.h.ProvinceCacheHandler;
import th.go.drr.gps.web.model.ProvinceList;

@Controller
@RequestMapping("/province")
public class ProvinceRestClient {

	private static Logger logger = Logger.getLogger(ProvinceRestClient.class);
	
	private Jaxb2Marshaller jaxb2Mashaller;	
	private ProvinceCacheHandler provinceCache;
	
	@RequestMapping(method=RequestMethod.GET, value="/{id}", headers="Accept=application/json,application/xml",produces = "application/json;charset=utf-8")
	@ResponseBody public Province  findProvinceByName(@PathVariable Integer id) {
			logger.info(id);
			return provinceCache.findById(id);
	}
	
	@RequestMapping(method=RequestMethod.GET, value="/all", headers="Accept=application/json,application/xml",produces = "application/json;charset=utf-8")
	@ResponseBody public ProvinceList  getAll() {		
		return new ProvinceList(this.provinceCache.findAll());
	}
	
	public void setJaxb2Mashaller(Jaxb2Marshaller jaxb2Mashaller) {
		this.jaxb2Mashaller = jaxb2Mashaller;
	}

	public void setProvinceCache(ProvinceCacheHandler provinceCache) {
		this.provinceCache = provinceCache;
	}			
}
